﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <link rel="stylesheet" href="../styles/table-transparent.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/datav.min.vue.js"></script>
  <script src="../Scripts/lodash.min.js"></script>
  <title>齐套性检查趋势看板</title>
  <style>
    html {
      background-image: url(../images/bg.jpg);
      color: #fff;
    }

    .header-title {
      font-size: 24px !important;
    }

    .el-form-item__label {
      color: #fff;
    }

    .el-form-item {
      margin-bottom: 0px;
    }

    .chart-title {
      text-align: center;
      padding-top: 10px;
      color: #fff;
    }

    .chart {
      width: 100%;
      font-size: 40px;
      font-weight: bold;
      cursor: pointer;
      text-align: center;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <div style="padding:0 10px;">
      <div class="parallelogram header-outer">
        <el-row>
          <el-col :span="7" style="padding-left: 35px;">
            <img src="../images/aeec_logo.png" height="60" alt="黎阳LOGO" />
          </el-col>
          <el-col :span="10" class="header-title">
            <div class="parallelogram header-inner">
              {{queryInfo.factoryname}}齐套性检查趋势看板
            </div>
          </el-col>
          <el-col :span="7" class="currentTime" style="padding-right: 35px;font-size: 18px;">
            {{currentTime}}
          </el-col>
        </el-row>
      </div>

      <!-- 查询区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules"
        style="margin:10px 10px 0 10px;">
        <el-form-item label="组织结构:" prop="selectOrg">
          <el-cascader :options="orginazition" :props="{ checkStrictly: true}" ref="orginazitionRef"
            v-model="queryInfo.selectOrg" clearable style="width:340px;">
          </el-cascader>
        </el-form-item>

        <el-form-item label="筛选时间:" prop="yearmonth">
          <el-date-picker v-model="queryInfo.yearmonth" type="month" value-format="yyyy-MM" style="width: 120px;"
            @change="selectYearMonthChange">
          </el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="handleSearchBtnClick">查询</el-button>
        </el-form-item>

        <el-form-item label="切换其他看板:">
          <el-select v-model="selectPageName" placeholder="请选择" filterable @change="reloadUrl">
            <el-option v-for="item in urlMap" :key="item.pagename" :label="item.name" :value="item.pagename">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>

      <el-row :gutter="10">
        <el-col :span="6">
          <dv-border-box-10>
            <h3 class="chart-title">工艺路线齐套率趋势</h3>
            <div class="chart" :style="{ height: chartHeight +'px' }" id="workflow-chart"></div>
          </dv-border-box-10>
        </el-col>

        <el-col :span="6">
          <dv-border-box-10>
            <h3 class="chart-title">排产数据齐套率</h3>
            <div class="chart" :style="{ height: chartHeight +'px' }" id="aps-chart"></div>
          </dv-border-box-10>
        </el-col>

        <el-col :span="6">
          <dv-border-box-10>
            <h3 class="chart-title">工装工具齐套率</h3>
            <div class="chart" :style="{ height: chartHeight +'px' }" id="tool-chart"></div>
          </dv-border-box-10>
        </el-col>

        <el-col :span="6">
          <dv-border-box-10>
            <h3 class="chart-title">生产物资齐套率</h3>
            <div class="chart" :style="{ height: chartHeight +'px' }" id="material-chart"></div>
          </dv-border-box-10>
        </el-col>
      </el-row>

      <el-row :gutter="10">
        <el-col :span="6">
          <dv-border-box-10>
            <h3 class="chart-title">设备状态齐套率</h3>
            <div class="chart" :style="{ height: chartHeight +'px' }" id="resources-chart"></div>
          </dv-border-box-10>
        </el-col>

        <el-col :span="6">
          <dv-border-box-10>
            <h3 class="chart-title">特殊过程齐套率</h3>
            <div class="chart" :style="{ height: chartHeight +'px' }" id="spotcheck-chart"></div>
          </dv-border-box-10>
        </el-col>

        <el-col :span="6">
          <dv-border-box-10>
            <h3 class="chart-title">质量预警</h3>
            <div class="chart" :style="{ height: chartHeight +'px' }" id="quality-chart"></div>
          </dv-border-box-10>
        </el-col>

        <el-col :span="6">
          <dv-border-box-10>
            <h3 class="chart-title">数控程序</h3>
            <div class="chart" :style="{ height: chartHeight +'px' }" id="ncprogram-chart"></div>
          </dv-border-box-10>
        </el-col>
      </el-row>

      <!-- 明细对话框 -->
      <el-dialog :title="chartDetail.title" :width="'98%'" :top="'10px'" :center="'center'"
        :visible.sync="chartDetail.dialogVisiable">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="chartDetail.dataList" stripe border>
          <el-table-column type="index" width="50"></el-table-column>
          <el-table-column label="操作" width="100">
            <template slot-scope="scope">
              <el-button type="primary" icon="el-icon-download" size="mini" @click="exportDetail">
                导出
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="批次号" prop="containername"></el-table-column>
          <el-table-column label="工序" prop="workflowstepname"></el-table-column>
          <el-table-column label="主制分厂" prop="fromfactoryname" width="100"></el-table-column>
          <el-table-column label="转工计划开始时间" prop="starttime" width="160">
            <template slot-scope="scope">
              <span v-if="scope.row.starttime">{{scope.row.starttime.replace('T',' ')}}</span>
            </template>
          </el-table-column>
          <el-table-column label="转工计划完成时间" prop="endtime" width="160">
            <template slot-scope="scope">
              <span v-if="scope.row.endtime">{{scope.row.endtime.replace('T',' ')}}</span>
            </template>
          </el-table-column>
          <el-table-column label="工艺类型" prop="spectypename" width="100"></el-table-column>
          <el-table-column label="工艺路线齐套" prop="iscompworkflow" width="120">
            <template slot-scope="scope">
              <el-tag effect="dark" :type="scope.row.iscompworkflow === 1 ? 'success' : 'danger'">
                {{scope.row.iscompworkflow === 1 ? '是' : '否'}}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="排产数据齐套" prop="iscompaps" width="120">
            <template slot-scope="scope">
              <el-tag effect="dark" :type="scope.row.iscompaps === 1 ? 'success' : 'danger'">
                {{scope.row.iscompaps === 1 ? '是' : '否'}}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="工装工具齐套" prop="iscomptool" width="120">
            <template slot-scope="scope">
              <el-tag effect="dark" :type="scope.row.iscomptool === 1 ? 'success' : 'danger'">
                {{scope.row.iscomptool === 1 ? '是' : '否'}}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="生产物资齐套" prop="iscompmaterial" width="120">
            <template slot-scope="scope">
              <el-tag effect="dark" :type="scope.row.iscompmaterial === 1 ? 'success' : 'danger'">
                {{scope.row.iscompmaterial === 1 ? '是' : '否'}}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="设备状态齐套" prop="iscompresource" width="120">
            <template slot-scope="scope">
              <el-tag effect="dark" :type="scope.row.iscompresource === 1 ? 'success' : 'danger'">
                {{scope.row.iscompresource === 1 ? '是' : '否'}}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="特殊过程齐套" prop="iscompspotcheck" width="120">
            <template slot-scope="scope">
              <el-tag effect="dark" :type="scope.row.iscompspotcheck === 1 ? 'success' : 'danger'">
                {{scope.row.iscompspotcheck === 1 ? '是' : '否'}}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="质量预警" prop="iscompquality" width="120">
            <template slot-scope="scope">
              <el-tag effect="dark" :type="scope.row.iscompquality === 1 ? 'success' : 'danger'">
                {{scope.row.iscompquality === 1 ? '是' : '否'}}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="报废数" prop="lossqty" width="60"></el-table-column>
          <el-table-column label="返修数" prop="reworkqty" width="60"></el-table-column>
        </el-table>
        <el-pagination @current-change="handleDetailCurrentChange" :current-page="chartDetail.queryInfo.currentPage"
          :page-sizes="[chartDetail.queryInfo.pageSize]" :page-size="chartDetail.queryInfo.pageSize"
          layout="prev,pager,next,jumper,sizes,total" :total="chartDetail.total">
        </el-pagination>
      </el-dialog>
    </div>
  </div>
  <script src=" ../Scripts/echarts/echarts-5.4.0.min.js">
  </script>
  <script type="module">
    import { exportExcelData, getParams } from '../Scripts/hooks/useCommonMethod.js'
    import { barOption, colorList } from '../Scripts/hooks/chartConfig.js'
    import { getMESOrginazition, getFactoryInfo } from '../Scripts/hooks/fetchAPI.js'
    const app = new Vue({
      el: '#app',
      data: {
        loading: false,
        loadingText: '数据加载中...',
        currentTime: '',
        orginazition: [],
        queryInfo: {
          yearmonth: '',
          thismonth: '',
          startOfSelectMonth: '',
          endOfSelectMonth: '',
          today: '',
          selectOrg: '',
          factoryname: ''
        },
        dataList: [],
        rules: {
          selectOrg: [{ required: true, message: '组织结构不能为空', trigger: 'change' }],
          yearmonth: [{ required: true, message: '筛选时间不能为空', trigger: 'change' }]
        },
        loadingConfig: { text: '数据查询中...', effect: 'whirling', maskColor: 'transparent', textColor: '#000', color: '#66b1ff' },
        chartDetail: {
          dialogVisiable: false, dataList: [], title: '',
          queryInfo: {
            id: '', day: '',
            currentPage: 1, pageSize: 10
          },
          total: 0
        },
        mapping: [
          { id: 'workflow-chart', label: '工艺路线齐套率', fieldname: 'workflowrate' },
          { id: 'aps-chart', label: '排产数据齐套率', fieldname: 'apsrate' },
          { id: 'tool-chart', label: '工装工具齐套率', fieldname: 'toolrate' },
          { id: 'material-chart', label: '生产物资齐套率', fieldname: 'materialrate' },
          { id: 'resources-chart', label: '设备状态齐套率', fieldname: 'resourcesrate' },
          { id: 'spotcheck-chart', label: '特殊过程齐套率', fieldname: 'spotcheckrate' },
          { id: 'quality-chart', label: '质量预警', fieldname: 'qualityrate' },
          { id: 'ncprogram-chart', label: '数控程序', fieldname: 'ncprogramrate' },
        ],
        chartHeight: (window.innerHeight - 270) / 2,
        apiUrl: '../handler/board/RbCompleteSetRateChartDashBoard.ashx',
        selectPageName: '',
        urlMap: [
          { name: '专项计划统计看板', pagename: 'RbSpecialItemPlanCountDashBoard' },
          { name: '齐套性检查趋势看板', pagename: 'RBCompleteSetRateChartDashBoard' },
          { name: 'APS排产统计看板', pagename: 'RbApsShipFinishDashBoardV2' },
          { name: '转工看板(生产作业会)', pagename: 'ContainerShipDashBoardSCB' },
        ]
      },
      methods: {
        selectYearMonthChange(val) {
          if (val) {
            this.queryInfo.startOfSelectMonth = dayjs(this.queryInfo.yearmonth).startOf('month').format('YYYY-MM-DD');
            this.queryInfo.endOfSelectMonth = dayjs(this.queryInfo.yearmonth).endOf('month').format('YYYY-MM-DD');
          }
        },
        // 生成折现图方法
        createChart({ id, data, chartColor }) {
          const fieldname = this.mapping.filter(i => i.id === id)[0].fieldname;
          const dom = document.getElementById(id);
          echarts.dispose(dom);
          let chart = echarts.init(dom);
          chart.showLoading(this.loadingConfig);

          echarts.dispose(dom);
          chart = echarts.init(dom);

          let arrDate = [], arrQty = [];
          for (const i of data) {
            if (this.queryInfo.yearmonth === this.queryInfo.thismonth) {
              if (dayjs().isAfter(i.monthday)) {
                arrDate.push(i.day);
                // 当天没有值，默认齐套率100%
                arrQty.push(i['starttime'] ? i[fieldname] : 100);
              }
            } else {
              arrDate.push(i.day);
              arrQty.push(i['starttime'] ? i[fieldname] : 100);
            }
          }

          let option = barOption({ showDataZoom: true, startValue: 0, endValue: 7 });
          option.legend.data = ['齐套率'];//设置图例文字
          option.xAxis.data = arrDate;
          option.yAxis[1].show = false;
          option.yAxis[0].axisLabel.formatter = function (data) { return data + "%"; };//y轴文字追加%

          const { color, colorStops } = colorList[chartColor] ? colorList[chartColor] : colorList.blue;
          option.series[0] = _.merge(option.series[0], {
            name: '齐套率',
            data: arrQty,
            type: 'line',
            smooth: true,
            areaStyle: {
              opacity: 0.8,
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, colorStops)
            },
            symbolSize: 10,
            lineStyle: { width: 3, color: color },
            // 旋转30°
            label: { color: color, formatter: '{c}%', rotate: 30 },
            itemStyle: { color: color }
          });

          chart.setOption(option);
          window.addEventListener('resize', () => {
            chart.resize();
          });

          chart.on('click', (params) => {
            const { seriesName, name, value } = params;
            if (value == 100) { return this.$message.error('仅可查询未齐套的数据明细') };
            this.chartDetail.queryInfo.currentPage = 1;
            this.chartDetail.queryInfo.id = id;
            this.chartDetail.queryInfo.day = name;
            this.getDetail({ id, day: name });
          })
        },
        async getData() {
          const { data: { data, meta } } = await axios.post(`${this.apiUrl}?action=getData`, {
            type: 'getData', ...this.queryInfo
          })
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }
          this.createChart({ id: 'workflow-chart', data, chartColor: 'blue' });
          this.createChart({ id: 'aps-chart', data, chartColor: 'blue' });
          this.createChart({ id: 'tool-chart', data, chartColor: 'blue' });
          this.createChart({ id: 'material-chart', data, chartColor: 'blue' });
          this.createChart({ id: 'resources-chart', data, chartColor: 'green' });
          this.createChart({ id: 'spotcheck-chart', data, chartColor: 'green' });
          this.createChart({ id: 'quality-chart', data, chartColor: 'green' });
          this.createChart({ id: 'ncprogram-chart', data, chartColor: 'green' });
        },
        // 查询未齐套明细
        async getDetail({ id, day }) {
          const label = this.mapping.filter(i => i.id === id)[0].label;
          const fieldname = this.mapping.filter(i => i.id === id)[0].fieldname;
          const date = `${this.queryInfo.yearmonth}-${day <= 9 ? ('0' + day) : day}`;

          this.chartDetail.title = `【${date}】【${label}】明细数据`;
          this.chartDetail.dialogVisiable = true;

          this.loading = true;
          this.loadingText = '数据查询中...';

          const { data: { data, meta, total } } = await axios({
            method: 'post',
            url: `${this.apiUrl}?action=getDetail`,
            data: { type: 'getDetail', ...this.queryInfo, ...this.chartDetail.queryInfo, seriesName: fieldname, date }
          })

          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.chartDetail.dataList = data;
          this.chartDetail.total = total;
        },
        handleSearchBtnClick() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (valid) {
              this.getData();
            }
          });
        },
        // 对话框分页事件
        handleDetailCurrentChange(newPage) {
          this.chartDetail.queryInfo.currentPage = newPage;
          const { id, day } = this.chartDetail.queryInfo;
          this.getDetail({ id, day });
        },
        exportDetail() {
          const { id, day } = this.chartDetail.queryInfo;
          const fieldname = this.mapping.filter(i => i.id === id)[0].fieldname;
          const date = `${this.queryInfo.yearmonth}-${day <= 9 ? ('0' + day) : day}`;
          const config = {
            url: `${this.apiUrl}?action=exportExcel`,
            data: {
              type: 'exportExcel',
              ...this.queryInfo,
              ...this.chartDetail.queryInfo,
              seriesName: fieldname,
              date,
              title: this.chartDetail.title
            }
          }
          exportExcelData(config, this);
        },
        reloadUrl() {
          const pagename = this.selectPageName;
          let { origin, search } = window.location;
          const url = `${origin}/MESReport/kanban/${pagename}.html${search}`;
          location.href = url;
        }
      },
      async mounted() {
        let incrementNumber = () => {
          setTimeout(incrementNumber, 1000);
          const weekDayText = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][dayjs().format('d')];
          this.currentTime = `${dayjs().format('YYYY年MM月DD日')} ${weekDayText} ${dayjs().format('HH:mm')}`;
        }
        setTimeout(incrementNumber, 500);

        this.queryInfo.yearmonth = dayjs().format('YYYY-MM');
        this.queryInfo.thismonth = dayjs().format('YYYY-MM');
        this.queryInfo.today = dayjs().format('YYYY-MM-DD');
        this.queryInfo.startOfSelectMonth = dayjs(this.queryInfo.yearmonth).startOf('month').format('YYYY-MM-DD');
        this.queryInfo.endOfSelectMonth = dayjs(this.queryInfo.yearmonth).endOf('month').format('YYYY-MM-DD');

        const factoryInfo = await getFactoryInfo({ factoryid: Decrypt(getParams('factoryid')), isMapping: '是' });
        const { factoryname } = factoryInfo[0];
        this.queryInfo.factoryname = factoryname;
        this.orginazition = await getMESOrginazition({ isMapping: '是', factoryCode: '602' });
        this.queryInfo.selectOrg = [this.orginazition[0].value];
        this.getData();
        window.addEventListener('resize', () => {
          this.chartHeight = (window.innerHeight - 270) / 2
        });
      }
    })
  </script>
</body>

</html>